cmake_minimum_required(VERSION 3.23.0)

set(MAPLE_ROOT $ENV{MAPLE_ROOT})
set(LINARO ${MAPLE_ROOT}/tools/gcc-linaro-7.5.0)

set(inc_dirs
${MAPLE_ROOT}/src/mrt/libsan/asan
${MAPLE_ROOT}/src/mrt/libsan/interception
${LINARO}/aarch64-linux-gnu/include/c++/7.5.0
${LINARO}/aarch64-linux-gnu/include/c++/7.5.0/aarch64-linux-gnu
${LINARO}/aarch64-linux-gnu/libc/usr/include
${LINARO}/lib/gcc/aarch64-linux-gnu/7.5.0/include
${LINARO}/aarch64-linux-gnu/libc/usr/include/linux
)

set(src_libsan
asan/asan_interceptors.cpp
asan/asan_report.cpp
asan/sanitizer_libc.cpp
asan/asan_stubs.cpp
asan/asan_malloc_linux.cpp
asan/sanitizer_termination.cpp
asan/asan_flags.cpp
asan/sanitizer_flags.cpp
asan/asan_rtl.cpp
asan/sanitizer_printf.cpp
asan/asan_shadow_memory.cpp
asan/sanitizer_linux_syscall.cpp
asan/asan_alloctor.cpp
asan/asan_mapping.cpp
asan/asan_fake_stack.cpp
asan/asan_interceptors_memintrinsics.cpp
asan/asan_signal_handler_linux.cpp
asan/asan_poisoning.cpp
asan/asan_avltree.cpp
interception/interception_linux.cpp
)

add_library(asan-dynamic SHARED ${src_libsan})
add_library(asan-static STATIC ${src_libsan})

# set(CMAKE_C_COMPILER ${MAPLE_ROOT}/output/tools/gcc-linaro-7.5.0/bin/aarch64-linux-gnu-gcc)
# set(CMAKE_CXX_COMPILER ${MAPLE_ROOT}/output/tools/gcc-linaro-7.5.0/bin/aarch64-linux-gnu-g++)

set(CMAKE_C_COMPILER ${LINARO}/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${LINARO}/bin/aarch64-linux-gnu-g++)

set_target_properties(asan-dynamic PROPERTIES
  COMPILE_FLAGS "-O3 -g -nostdinc -nostdinc++ -fno-exceptions"
  INCLUDE_DIRECTORIES "${inc_dirs}"
  LINK_LIBRARIES ""
  OUTPUT_NAME "asan"
)

set_target_properties(asan-static PROPERTIES
  COMPILE_FLAGS "-O3 -g -nostdinc -nostdinc++ -fno-exceptions"
  INCLUDE_DIRECTORIES "${inc_dirs}"
  LINK_LIBRARIES ""
  OUTPUT_NAME "asan"
)
